package logic

import (
	"context"
	"taobao-merchandise/taobaoRpc/taobaoRpc"

	"taobao-merchandise/api/internal/svc"
	"taobao-merchandise/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateGoodLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateGoodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateGoodLogic {
	return &UpdateGoodLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateGoodLogic) UpdateGood(req *types.UpdateGoodRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	uodate, err := l.svcCtx.TaoBaoRPc.UpdateGood(l.ctx, &taobaoRpc.UpdateGoodRequest{
		UserId: req.UserId,
		Id:     req.Id,
		Image:  req.Image,
		Title:  req.Title,
		Price:  float32(req.Price),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "商品修改成功",
		Code:    200,
		Data:    uodate,
	}, nil
}
